﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FastKnow.Cache
{
    /// <summary>
    /// 缓存项的包装类
    /// </summary>
    [Serializable]
    public class CacheItem
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="key">缓存项健值</param>
        /// <param name="value">储存项值</param>
        /// <param name="cacheDependency">过期策略</param>
        public CacheItem(string key, object @value, ICacheDependency cacheDependency)
        {
            this.key = key;
            this.value = @value;
            this.cacheDependency = cacheDependency;
            this.hits = 0;
            this.lastAccessTime = DateTime.Now;
        }

        private string key;
        private object @value;
        private ICacheDependency cacheDependency;
        private int hits;
        private DateTime lastAccessTime;

        /// <summary>
        /// 获取过期策略
        /// </summary>
        public ICacheDependency CacheDependency
        {
            get { return this.cacheDependency; }
        }

        /// <summary>
        /// 获取健值
        /// </summary>
        public string Key
        {
            get { return this.key; }
        }

        /// <summary>
        /// 获取缓存项
        /// </summary>
        public object Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        /// <summary>
        /// 命中次数
        /// </summary>
        public int Hits
        {
            get { return this.hits; }
            set { this.hits = value; }
        }

        /// <summary>
        /// 最后命中时间
        /// </summary>
        public DateTime LastAccessTime
        {
            get { return this.lastAccessTime; }
            set { this.lastAccessTime = value; }
        }
    }
}
